﻿using System;
using System.Collections.Generic;
using System.Text;
using TgcViewer;
using Microsoft.DirectX;
using TgcViewer.Utils._2D;
using TgcViewer.Utils.TgcGeometry;
using System.Drawing;

namespace AlumnoEjemplos.SEGUROLA_Y_HABANA_4310
{
    public class Wall
    {
        TgcQuad quad;
        TgcArrow normalArrow;
        bool showNormal;

        public Wall()
        {
            quad = new TgcQuad();

            //Modifiers para variar sus parametros
            GuiController.Instance.Modifiers.addVertex2f("size", new Vector2(0, 0), new Vector2(100, 100), new Vector2(100, 100));
            GuiController.Instance.Modifiers.addVertex3f("normal", new Vector3(-10, -10, -10), new Vector3(10, 10, 10), new Vector3(0, 0, 1));
            GuiController.Instance.Modifiers.addVertex3f("center", new Vector3(-100, -100, -100), new Vector3(100, 100, 100), new Vector3(0, 50, 0));
            GuiController.Instance.Modifiers.addColor("color", Color.Coral);

            //Flecha para mostrar el sentido del vector normal
            normalArrow = new TgcArrow();
            GuiController.Instance.Modifiers.addBoolean("showNormal", "Show normal", true);
            GuiController.Instance.RotCamera.CameraDistance = 50;

        }

        public void Update(float ElapsedTime)
        {

            Vector2 size = (Vector2)GuiController.Instance.Modifiers["size"];
            Vector3 normal = (Vector3)GuiController.Instance.Modifiers["normal"];
            Vector3 center = (Vector3)GuiController.Instance.Modifiers["center"];
            Color color = (Color)GuiController.Instance.Modifiers["color"];

            //Cargar valores del quad.
            quad.Center = center;
            quad.Size = size;
            quad.Normal = normal;
            quad.Color = color;

            //Actualizar valors para hacerlos efectivos
            quad.updateValues();

            showNormal = (bool)GuiController.Instance.Modifiers["showNormal"];

            //Actualizar valores de la flecha
            if (showNormal)
            {
                normalArrow.PStart = quad.Center;
                normalArrow.PEnd = quad.Center + quad.Normal * 10;
                normalArrow.updateValues();
            }
        }

        public void Render()
        {
            quad.render();

            if (showNormal)
            {
                normalArrow.render();
            }
        }

        public void Close()
        {
            quad.dispose();
            normalArrow.dispose();
        }
    }
}
